package com.ruoyi.web.controller.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.client.MesClientAll;
import com.ruoyi.system.service.IMesClientAllService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户端管理Controller
 *
 * @author ruoyi
 * @date 2023-02-20
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/client/mes_client_all" )
public class MesClientAllController extends BaseController {

    private final IMesClientAllService iMesClientAllService;

    /**
     * 查询客户端管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MesClientAll mesClientAll)
    {
        startPage();
        LambdaQueryWrapper<MesClientAll> lqw = new LambdaQueryWrapper<MesClientAll>();
        if (StringUtils.isNotBlank(mesClientAll.getClientName())){
            lqw.like(MesClientAll::getClientName ,mesClientAll.getClientName());
        }
        if (StringUtils.isNotBlank(mesClientAll.getClientDescription())){
            lqw.like(MesClientAll::getClientDescription ,mesClientAll.getClientDescription());
        }
        if (StringUtils.isNotBlank(mesClientAll.getClientStatus())){
            lqw.eq(MesClientAll::getClientStatus ,mesClientAll.getClientStatus());
        }
        if (StringUtils.isNotBlank(mesClientAll.getClientType())){
            lqw.eq(MesClientAll::getClientType ,mesClientAll.getClientType());
        }
        if (StringUtils.isNotBlank(mesClientAll.getField2())){
            lqw.eq(MesClientAll::getField2 ,mesClientAll.getField2());
        }
        if (StringUtils.isNotBlank(mesClientAll.getField3())){
            lqw.eq(MesClientAll::getField3 ,mesClientAll.getField3());
        }
        if (mesClientAll.getField4() != null){
            lqw.eq(MesClientAll::getField4 ,mesClientAll.getField4());
        }
        List<MesClientAll> list = iMesClientAllService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出客户端管理列表
     */
    @Log(title = "客户端管理" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MesClientAll mesClientAll) {
        LambdaQueryWrapper<MesClientAll> lqw = new LambdaQueryWrapper<MesClientAll>(mesClientAll);
        List<MesClientAll> list = iMesClientAllService.list(lqw);
        ExcelUtil<MesClientAll> util = new ExcelUtil<MesClientAll>(MesClientAll. class);
        return util.exportExcel(list, "mes_client_all" );
    }

    /**
     * 获取客户端管理详细信息
     */
    @GetMapping(value = "/{clientId}" )
    public AjaxResult getInfo(@PathVariable("clientId" ) Long clientId) {
        return AjaxResult.success(iMesClientAllService.getById(clientId));
    }

    /**
     * 新增客户端管理
     */
    @Log(title = "客户端管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesClientAll mesClientAll) {
        return toAjax(iMesClientAllService.save(mesClientAll) ? 1 : 0);
    }

    /**
     * 修改客户端管理
     */
    @Log(title = "客户端管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesClientAll mesClientAll) {
        return toAjax(iMesClientAllService.updateById(mesClientAll) ? 1 : 0);
    }

    /**
     * 删除客户端管理
     */
    @Log(title = "客户端管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{clientIds}" )
    public AjaxResult remove(@PathVariable Long[] clientIds) {
        return toAjax(iMesClientAllService.removeByIds(Arrays.asList(clientIds)) ? 1 : 0);
    }
}
